import request from "./request";
import mockRequest from "@/api/mockRequest";

// 获取商品种类 /api/product/getBaseCategoryList
export const reqGetCategoryList = () =>
  request.get("/product/getBaseCategoryList");

// 搜索商品 /api/list
export const reqGetProdList = (data) => request.post("/list", data);
// 商品单个信息 /api/item/{ skuId }
export const reqProdDetail = (skuId) => request.get(`/item/${skuId}`);
/**
 * 添加到购物车
 * /api/cart/addToCart/{ skuId }/{ skuNum }
 * @param {*} id
 * @param {*} num
 * @returns
 */
export const reqAddProdOrder = (id, num) =>
  request.post(`/cart/addToCart/${id}/${num}`);
/**
 * 获取购物车列表
 * /api/cart/cartList
 * @returns
 */
export const reqGetCartList = () => request.get("/cart/cartList");
/**
 * 切换商品选中状态
 * @param {*} skuID
 * @param {*} isChecked
 * @returns
 */
export const reqChangeIsChecked = (skuID, isChecked) =>
  request.get(`/cart/checkCart/${skuID}/${isChecked}`);
/**
 * 商品全选
 * @param {*} isChecked
 * @param {*} data
 * @returns
 */
export const reqChangeAllChecked = (isChecked, data) =>
  request.post(`/cart/batchCheckCart/${isChecked}`, data);
/**
 * 删除单个商品
 * @param {*} skuId
 * @returns
 */
export const reqDelOneProd = (skuId) =>
  request.delete(`/cart/deleteCart/${skuId}`);
/**
 * 批量删除
 * @param {*} ids
 * @returns
 */
export const reqDelBatchProds = (ids) =>
  request.post("/cart/batchDeleteCart", ids);
/**
 * 获取验证码
 * /api/user/passport/sendCode/{phone}
 * @param {*} phone
 * @returns
 */
export const reqGetPhoneCode = (phone) =>
  request.get(`/user/passport/sendCode/${phone}`);
/**
 * 注册
 * @param {*} data
 * @returns
 */
export const reqRegister = (data) =>
  request.post("/user/passport/register", data);
/**
 * 登录
 * @param {*} data
 * @returns
 */
export const reqLogin = (data) => request.post("/user/passport/login", data);
/**
 * 获取用户信息
 * @returns
 */
export const reqGetUserInfo = () =>
  request.get("/user/passport/auth/getUserInfo");
/**
 * 退出登录
 * @returns
 */
export const reqLogout = () => request.get("/user/passport/logout");
/**
 * 收货地址
 * @returns
 */
export const getMockAddrs = () => mockRequest("/address");
/**
 * 交易信息
 * @returns
 */
export const reqGetTradeInfo = () => request.get("/order/auth/trade");
/**
 * 提交订单
 * @param {*} tradeNo
 * @param {*} data
 * @returns
 */
export const reqSubmitOrder = (tradeNo, data) =>
  request.post(`/order/auth/submitOrder?tradeNo=${tradeNo}`, data);
/**
 * 查询订单信息
 * @param {*} orderId
 * @returns
 */
export const reqGetOrderInfo = (orderId) =>
  request.get(`/payment/weixin/createNative/${orderId}`);
/**
 *订单支付状态
 * @param {*} orderId
 * @returns
 */
export const reqGetPayStatus = (orderId) =>
  request.get(`/payment/weixin/queryPayStatus/${orderId}`);
/**
 *我的订单
 * @param {*} page
 * @param {*} limit
 * @returns
 */
export const reqGetOrderList = (page, limit) =>
  request.get(`/order/auth/${page}/${limit}`);

/**
 * mock数据
 */
// 轮播图 /banner
export const getMockBannerList = () => mockRequest("/banner");
export const getMockFloorList = () => mockRequest("/floor");
export default {
  reqProdDetail,
  reqAddProdOrder,
  reqGetCartList,
  reqChangeIsChecked,
  reqChangeAllChecked,
  reqDelOneProd,
  reqDelBatchProds,
  reqGetPhoneCode,
  reqRegister,
  reqLogin,
  getMockAddrs,
  reqGetTradeInfo,
  reqSubmitOrder,
  reqGetOrderInfo,
  reqGetPayStatus,
  reqGetOrderList,
};
